const express = require('express');
const app = express();

// 根据 params 路由参数 访问 不同页面
// GET http://127.0.0.1:8080/frontend.html
// GET http://127.0.0.1:8080/backend.html
// GET http://127.0.0.1:8080/vue.html

app.get('/:p.html',(request,response)=>{
    //通过request.params 获取路由参数（params参数） p
    console.log(request.params)
    let p = request.params.p;
    if(p === 'frontend'){
        response.send(`<h1>前端页面</h1>
        <a href="/frontend.html">前端页面</a>
        <a href="/backend.html">后端页面</a>
        <a href="/vue.html">vue页面</a>`)
    }
    if(p === 'backend'){
        response.send(`<h1>后端页面</h1>
        <a href="/frontend.html">前端页面</a>
        <a href="/backend.html">后端页面</a>
        <a href="/vue.html">vue页面</a>`)
    }
    if(p === 'vue'){
        response.send(`<h1>vue页面</h1>
        <a href="/frontend.html">前端页面</a>
        <a href="/backend.html">后端页面</a>
        <a href="/vue.html">vue页面</a>`)
    }
})

app.listen(8080,()=>{console.log('server run at 8080')})